'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);
  // 会员登录注册
  router.post('/api/member/login', controller.member.login);
  router.post('/api/member/register', controller.member.register);

  // 后台用户
  router.post('/api/user/login', controller.user.login);
  router.get('/api/user/list', controller.user.allList);
  router.resources('user', '/api/user', controller.user);
  // 角色
    router.get('/api/role/list', controller.role.allList);
    router.resources('role', '/api/role', controller.role);

  // banner
  router.get('/api/banner/list', controller.banner.allList);
  router.resources('banner', '/api/banner', controller.banner);
  // 优惠券
  router.get('/api/coupon/list', controller.coupon.allList);
  router.resources('coupon', '/api/coupon', controller.coupon);
  // 优惠券领取
  router.get('/api/couponMember/list', controller.couponMember.allList);
  router.resources('couponMember', '/api/couponMember', controller.couponMember);
  // 收藏
  router.get('/api/collect/list', controller.collect.allList);
  router.resources('collect', '/api/collect', controller.collect);
  // 商品分类
  router.get('/api/category/list', controller.category.allList);
  router.get('/api/category/productList', controller.category.productList);
  router.resources('category', '/api/category', controller.category);
  // 商品
  router.get('/api/goods/list', controller.goods.allList);
  router.resources('goods', '/api/goods', controller.goods);
  // 商品订单
  router.get('/api/orderGoods/list', controller.orderGoods.allList);
  // 导出
    router.get('/api/orderGoods/export', controller.orderGoods.export);
  router.resources('orderGoods', '/api/orderGoods', controller.orderGoods);
  router.resources('orderGoodsDetail', '/api/orderGoodsDetail', controller.orderGoodsDetail);
  router.resources('express', '/api/express', controller.express);
  // 会员
  router.get('/api/member/list', controller.member.allList);
  router.resources('member', '/api/member', controller.member);
  // 地址
  router.get('/api/address/list', controller.address.allList);
  router.post('/api/address/updateStatus', controller.address.updateStatus);
  router.resources('address', '/api/address', controller.address);
};
